const Router = require('koa-router');
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");


router.post('/common/listByMod', async ctx => {
    let mod = ctx.request.body.mod
    let order = ctx.request.body.order
    if (mod) {
        let options = {}
        if(order) {
            // sort,desc|s,asc
            let sort = order.split('|')
            let ord = []
            for (let i = 0; i < sort.length; i++) {
                if(sort[i]) {
                    let inn = sort[i].split(',')
                    if(inn.length === 2) {
                        ord.push(inn)
                    }
                }
            }
            if(ord.length > 0)
                options.order = ord
        }
        let list = await db.models[mod].findAll(options)
        return ctx.suc('', list)
    }
    return  ctx.suc('', [])
})






module.exports = router;